
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { invokeAPi } from '@/xz-fn.js'
Vue.use(VueI18n) // 全局注册国际化包

const langFileds = require.context('./config', false, /\.js$/)
const messages = {}
// eslint-disable-next-line no-useless-escape
const regExp = /\.\/([^\.\/]+)\.([^\.]+)$/
const lang = invokeAPi('xz_get_language') || 'zh'
langFileds.keys().forEach(key => {
  const prop = regExp.exec(key)[1]
  messages[prop] = langFileds(key).default
})
const locale = messages[lang] ? lang : 'en'
export default new VueI18n({
  locale,
  messages
})
